package com.bjxst;

import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.FileInputStream;
import java.io.FileOutputStream;

public class FileCopyTools02 {
    public static void main(String[] args) {
        copyFile02("e:/picture/1002.jpg","e:/ee.jpg");

    }
    public static void copyFile02(String src,String des){
        FileInputStream fis = null;
        BufferedInputStream bis = null;
        FileOutputStream fos = null;
        BufferedOutputStream bos = null;
        try{
            //创建对象
            bis = new BufferedInputStream(new FileInputStream(src));
            bos = new BufferedOutputStream(new FileOutputStream(des));
            int temp =0;
            while ((temp = bis.read()) != -1){
                bos.write(temp);
            }
            bos.flush();
        }catch (Exception e){
            e.printStackTrace();
        }finally {
            //注意关闭顺序 后开先关
            try{
                if(bis != null){
                    bis.close();
                }
                if(fis != null){
                    fis.close();
                }
                if(bos != null){
                    bos.close();
                }
                if(fos != null){
                    bis.close();
                }
            }catch (Exception e){
                e.printStackTrace();
            }
        }

    }
}
